<%#
 Copyright 2013-2019 the original author or authors from the JHipster project.

 This file is part of the JHipster project, see https://www.jhipster.tech/
 for more information.

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
-%>
package <%=packageName%>.domain;<%
let importApiModelProperty = false;
let importJsonIgnore = false;
let importJsonIgnoreProperties = false;
let importSet = false;
let hasDto = dto === 'mapstruct';
let isUsingMapsId = false;
let primaryKeyType = pkType;
let hasTextBlob = false;
let hasRelationship = relationships.length !== 0;
const uniqueEnums = {}; %><%- include imports -%>
<%_ for (idx in relationships) {
        isUsingMapsId = relationships[idx].useJPADerivedIdentifier;
        if ( isUsingMapsId === true) {
            primaryKeyType = (relationships[idx].otherEntityName === 'user'  && authenticationType === 'oauth2') ? 'String' : pkType;
            break;
        }
        isUsingMapsId = false;
    }
    for (idx in fields) {
        if ((prodDatabaseType === 'postgresql' || devDatabaseType === 'postgresql') && fields[idx].fieldTypeBlobContent === 'text') {
            hasTextBlob = true;
            break;
        }
    } _%>
<%_ if (databaseType === 'cassandra') { _%>
import org.springframework.data.annotation.Id;
    <%_ if (fieldsContainBlob) { _%>
import org.springframework.data.cassandra.core.mapping.Column;
    <%_ } _%>
import org.springframework.data.cassandra.core.mapping.Table;
<%_ } if (importJsonIgnore === true) { _%>
import com.fasterxml.jackson.annotation.JsonIgnore;
<%_ } if (importJsonIgnoreProperties === true) { _%>
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
<%_ } if (!hasDto && typeof javadoc != 'undefined') { _%>
import io.swagger.annotations.ApiModel;
<%_ } if (!hasDto && importApiModelProperty === true) { _%>
import io.swagger.annotations.ApiModelProperty;
<%_ } if (enableHibernateCache) { _%>
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
<%_ } if (hasTextBlob === true || (fieldsContainUUID === true && ['mysql', 'mariadb'].includes(prodDatabaseType))) { _%>
import org.hibernate.annotations.Type;
<%_ } if (databaseType === 'mongodb') { _%>
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Field;
import org.springframework.data.mongodb.core.mapping.Document;
    <%_ if (hasRelationship) { _%>
import org.springframework.data.mongodb.core.mapping.DBRef;
    <%_ } _%>
<%_ } else if (databaseType === 'couchbase') { _%>
import org.springframework.data.annotation.Id;
import com.couchbase.client.java.repository.annotation.Field;
import org.springframework.data.couchbase.core.mapping.Document;
import org.springframework.data.couchbase.core.mapping.id.GeneratedValue;
import org.springframework.data.couchbase.core.mapping.id.IdPrefix;
    <%_ if (hasRelationship) { _%>
import org.springframework.data.couchbase.core.query.FetchType;
import org.springframework.data.couchbase.core.query.N1qlJoin;
    <%_ } _%>
<%_ } if (databaseType === 'sql') { _%>

import javax.persistence.*;
<%_ } if (validation) { _%>
import javax.validation.constraints.*;
<%_ } _%>

<%_ if (searchEngine === 'elasticsearch') { _%>
import org.springframework.data.elasticsearch.annotations.FieldType;
<%_ } _%>
import java.io.Serializable;
<%_ if (fieldsContainBigDecimal === true) { _%>
import java.math.BigDecimal;
<%_ } if (fieldsContainBlob && databaseType === 'cassandra') { _%>
import java.nio.ByteBuffer;
<%_ } if (fieldsContainInstant === true) { _%>
import java.time.Instant;
<%_ } if (fieldsContainLocalDate === true) { _%>
import java.time.LocalDate;
<%_ } if (fieldsContainZonedDateTime === true) { _%>
import java.time.ZonedDateTime;
<%_ } if (fieldsContainDuration === true) { _%>
import java.time.Duration;
<%_ } if (importSet === true) { _%>
import java.util.HashSet;
import java.util.Set;
<%_ } if (databaseType === 'couchbase' && hasRelationship) { _%>
import java.util.stream.Collectors;
<%_ } _%>
<%_ if (databaseType === 'cassandra' || fieldsContainUUID === true) { _%>
import java.util.UUID;
<%_ }
Object.keys(uniqueEnums).forEach(function(element) { _%>

import <%=packageName%>.domain.enumeration.<%= element %>;
<%_ }); _%>

<%_ if (databaseType === 'couchbase') { _%>
import static <%=packageName%>.config.Constants.ID_DELIMITER;
import static org.springframework.data.couchbase.core.mapping.id.GenerationStrategy.UNIQUE;

<%_ } _%>
<%_ if (typeof javadoc == 'undefined') { _%>
/**
 * A <%= asEntity(entityClass) %>.
 */
<%_ } else { _%>
<%- formatAsClassJavadoc(javadoc) %>
    <%_ if (!hasDto) { _%>
@ApiModel(description = "<%- formatAsApiDescription(javadoc) %>")
    <%_ }_%>
<%_ } _%>
<%_ if (databaseType === 'sql') { _%>
@Entity
@Table(name = "<%= entityTableName %>")
<%_     if (enableHibernateCache) {
            if (cacheProvider === 'infinispan') { _%>
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
<%_         } else { _%>
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
<%_         }
        }
} if (databaseType === 'mongodb') { _%>
@Document(collection = "<%= entityTableName %>")
<%_ } if (databaseType === 'couchbase') { _%>
@Document
<%_ } if (databaseType === 'cassandra') { _%>
@Table("<%= entityInstance %>")
<%_ } if (searchEngine === 'elasticsearch') { _%>
@org.springframework.data.elasticsearch.annotations.Document(indexName = "<%= entityInstance.toLowerCase() %>")
<%_ } _%>
public class <%= asEntity(entityClass) %> implements Serializable {

    private static final long serialVersionUID = 1L;
    <%_ if (databaseType === 'couchbase') { _%>
    public static final String PREFIX = "<%= entityInstance.toLowerCase() %>";

    @SuppressWarnings("unused")
    @IdPrefix
    private String prefix = PREFIX;
    <%_ } _%>

    @Id
    <%_ if (databaseType === 'sql' && isUsingMapsId === false) { _%>
        <%_ if (prodDatabaseType === 'mysql' || prodDatabaseType === 'mariadb') { _%>
    @GeneratedValue(strategy = GenerationType.IDENTITY)
        <%_ }  else { _%>
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequenceGenerator")
    @SequenceGenerator(name = "sequenceGenerator")
        <%_ } _%>
    <%_ } _%>
    <%_ if (databaseType === 'couchbase') { _%>
    @GeneratedValue(strategy = UNIQUE, delimiter = ID_DELIMITER)
    <%_ } _%>
    <%_ if (searchEngine === 'elasticsearch') { _%>
    @org.springframework.data.elasticsearch.annotations.Field(type = FieldType.Keyword)
    <%_ } _%>
    private <%= primaryKeyType %> id;

<%_ for (idx in fields) {
    if (typeof fields[idx].javadoc !== 'undefined') { _%>
<%- formatAsFieldJavadoc(fields[idx].javadoc) %>
    <%_ }
    let required = false;
    let unique = false;
    const fieldValidate = fields[idx].fieldValidate;
    const fieldValidateRules = fields[idx].fieldValidateRules;
    const fieldValidateRulesMaxlength = fields[idx].fieldValidateRulesMaxlength;
    const fieldType = fields[idx].fieldType;
    const fieldTypeBlobContent = fields[idx].fieldTypeBlobContent;
    const fieldName = fields[idx].fieldName;
    const fieldNameUnderscored = fields[idx].fieldNameUnderscored;
    const fieldNameAsDatabaseColumn = fields[idx].fieldNameAsDatabaseColumn;
    if (fieldValidate === true) {
        if (fieldValidateRules.includes('required')) {
            required = true;
        }
        if (fieldValidateRules.includes('unique')) {
            unique = true;
        } _%>
    <%- include ../common/field_validators -%>
    <%_ } _%>
    <%_ if (!hasDto && typeof fields[idx].javadoc != 'undefined') { _%>
    @ApiModelProperty(value = "<%- formatAsApiDescription(fields[idx].javadoc) %>"<% if (required) { %>, required = true<% } %>)
    <%_ } _%>
    <%_ if (databaseType === 'sql') {
        if (fields[idx].fieldIsEnum) { _%>
    @Enumerated(EnumType.STRING)
        <%_ }
        if (fieldType === 'byte[]') { _%>
    @Lob
        <%_ if ((prodDatabaseType === 'postgresql' || devDatabaseType === 'postgresql') && fieldTypeBlobContent === 'text' ) { _%>
    @Type(type = "org.hibernate.type.TextType")
        <%_ }
        }
        if (['Instant', 'ZonedDateTime', 'LocalDate', 'Duration'].includes(fieldType)) { _%>
    @Column(name = "<%-fieldNameAsDatabaseColumn %>"<% if (required) { %>, nullable = false<% } %><% if (unique) { %>, unique = true<% } %>)
        <%_ } else if (fieldType === 'BigDecimal') { _%>
    @Column(name = "<%-fieldNameAsDatabaseColumn %>", precision = 21, scale = 2<% if (required) { %>, nullable = false<% } %><% if (unique) { %>, unique = true<% } %>)
        <%_ } else if (fieldType === 'UUID' && ['mysql', 'mariadb'].includes(prodDatabaseType)) { _%>
    @Type(type = "uuid-char")
    @Column(name = "<%-fieldNameAsDatabaseColumn %>", length = 36<% if (required) { %>, nullable = false<% } %><% if (unique) { %>, unique = true<% } %>)
        <%_ } else { _%>
    @Column(name = "<%-fieldNameAsDatabaseColumn %>"<% if (fieldValidate === true) { %><% if (fieldValidateRules.includes('maxlength')) { %>, length = <%= fieldValidateRulesMaxlength %><% } %><% if (required) { %>, nullable = false<% } %><% if (unique) { %>, unique = true<% } %><% } %>)
        <%_ }
    } _%>
    <%_ if (databaseType === 'mongodb' || databaseType === 'couchbase') { _%>
    @Field("<%=fieldNameUnderscored %>")
    <%_ } _%>
    <%_ if (fieldTypeBlobContent !== 'text') { _%>
    private <%= fieldType %> <%= fieldName %>;
    <%_ } else { _%>
    private String <%= fieldName %>;
    <%_ } _%>

    <%_ if ((fieldType === 'byte[]' || fieldType === 'ByteBuffer') && fieldTypeBlobContent !== 'text') { _%>
      <%_ if (databaseType === 'sql' || databaseType === 'cassandra') { _%>
    @Column(<% if (databaseType !== 'cassandra') { %>name = <% } %>"<%-fieldNameAsDatabaseColumn %>_content_type"<% if (required && databaseType !== 'cassandra') { %>, nullable = false<% } %>)
        <%_ if (required && databaseType === 'cassandra') { _%>
    @NotNull
        <%_ } _%>
      <%_ } _%>
      <%_ if (databaseType === 'mongodb' || databaseType === 'couchbase') { _%>
    @Field("<%=fieldNameUnderscored %>_content_type")
      <%_ } _%>
    private String <%= fieldName %>ContentType;

    <%_ }
    }

    for (idx in relationships) {
        const otherEntityRelationshipName = relationships[idx].otherEntityRelationshipName;
        const otherEntityRelationshipNamePlural = relationships[idx].otherEntityRelationshipNamePlural;
        const relationshipName = relationships[idx].relationshipName;
        const relationshipFieldName = relationships[idx].relationshipFieldName;
        const relationshipFieldNamePlural = relationships[idx].relationshipFieldNamePlural;
        const joinTableName = getJoinTableName(entityTableName, relationshipName, prodDatabaseType);
        const relationshipType = relationships[idx].relationshipType;
        const relationshipValidate = relationships[idx].relationshipValidate;
        const relationshipRequired = relationships[idx].relationshipRequired;
        const otherEntityNameCapitalized = relationships[idx].otherEntityNameCapitalized;
        const ownerSide = relationships[idx].ownerSide;
        const isUsingMapsId = relationships[idx].useJPADerivedIdentifier;
        if (otherEntityRelationshipName) {
            mappedBy = otherEntityRelationshipName.charAt(0).toLowerCase() + otherEntityRelationshipName.slice(1)
        }
        if (typeof relationships[idx].javadoc != 'undefined') { _%>
<%- formatAsFieldJavadoc(relationships[idx].javadoc) %>
            <%_ if (!hasDto) { _%>
    @ApiModelProperty(value = "<%- formatAsApiDescription(relationships[idx].javadoc) %>")
            <%_ }_%>
    <%_ }
        if (relationshipType === 'one-to-many') {
            if (databaseType === 'sql') {
    _%>
    @OneToMany(mappedBy = "<%= otherEntityRelationshipName %>")
            <%_ if (enableHibernateCache) {
                    if (cacheProvider === 'infinispan') { _%>
    @Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
                <%_ } else { _%>
    @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
                <%_ }
            }
        } else if (databaseType === 'mongodb' || databaseType === 'couchbase') {
            if (databaseType === 'mongodb') { _%>
    @DBRef
        <%_ } _%>
    @Field("<%= relationshipFieldName %>")
        <%_ if (databaseType === 'couchbase') { _%>
    private Set<String> <%= relationshipFieldName %>Ids = new HashSet<>();

    @N1qlJoin(on = "lks.<%= relationshipFieldName %>=meta(rks).id", fetchType = FetchType.IMMEDIATE)
        <%_ } _%>
    <%_ } _%>
    private Set<<%= asEntity(otherEntityNameCapitalized) %>> <%= relationshipFieldNamePlural %> = new HashSet<>();

    <%_ } else if (relationshipType === 'many-to-one') {
            if (databaseType === 'sql') {
    _%>
    @ManyToOne<% if (relationshipRequired) { %>(optional = false)<% } %>
        <%_ if (relationshipValidate) { _%>
    <%- include relationship_validators -%>
        <%_ }
    } else if (databaseType === 'mongodb' || databaseType === 'couchbase') {
        if (databaseType === 'mongodb') { _%>
    @DBRef
    <%_ } _%>
    @Field("<%= relationshipFieldName %>")
    <%_ if (databaseType === 'couchbase') { _%>
    private String <%= relationshipFieldName %>Id;

    @N1qlJoin(on = "lks.<%= relationshipFieldName %>=meta(rks).id", fetchType = FetchType.IMMEDIATE)
    <%_ }
    }
    _%>
    <%_ if (otherEntityRelationshipNamePlural !== undefined && otherEntityRelationshipNamePlural !== '') { _%>
    @JsonIgnoreProperties("<%= otherEntityRelationshipNamePlural %>")
    <%_ } _%>
    private <%= asEntity(otherEntityNameCapitalized) %> <%= relationshipFieldName %>;

    <%_ } else if (relationshipType === 'many-to-many') {
        if (databaseType === 'sql') { _%>
    @ManyToMany<% if (ownerSide === false) { %>(mappedBy = "<%= otherEntityRelationshipNamePlural %>")<% } %>
        <%_ if (enableHibernateCache) {
                if (cacheProvider === 'infinispan') { _%>
    @Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
            <%_ } else { _%>
    @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
            <%_ }
        } if (ownerSide === true) {
            if (relationshipValidate) { _%>
    <%- include relationship_validators -%>
        <%_ } _%>
    @JoinTable(name = "<%= joinTableName %>",
               joinColumns = @JoinColumn(name = "<%= getColumnName(name) %>_id", referencedColumnName = "id"),
               inverseJoinColumns = @JoinColumn(name = "<%= getColumnName(relationships[idx].relationshipName) %>_id", referencedColumnName = "id"))
        <%_ }
        } else if (databaseType === 'mongodb' || databaseType === 'couchbase') {
            if (databaseType === 'mongodb') { _%>
    @DBRef
        <%_ } _%>
    @Field("<%= relationshipFieldNamePlural %>")
        <%_ if (databaseType === 'couchbase') { _%>
    private Set<String> <%= relationshipFieldName %>Ids = new HashSet<>();

    @N1qlJoin(on = "lks.<%= relationshipFieldNamePlural %>=meta(rks).id", fetchType = FetchType.IMMEDIATE)
        <%_ }
         } if (ownerSide === false) { _%>
    @JsonIgnore
    <%_ } _%>
    private Set<<%= asEntity(otherEntityNameCapitalized) %>> <%= relationshipFieldNamePlural %> = new HashSet<>();

    <%_ } else {
        if (databaseType === 'sql') {
            if (ownerSide) { _%>
    @OneToOne<% if (relationshipRequired) { %>(optional = false)<% } %>
            <%_ if (relationshipValidate) { _%>
    <%- include relationship_validators -%>
            <%_ }_%>
            <%_ if (isUsingMapsId === true) { %>
    @MapsId
    @JoinColumn(name = "id")
            <%_ } else { _%>
    @JoinColumn(unique = true)
            <%_ } _%>
        <%_ } else { _%>
    @OneToOne(mappedBy = "<%= otherEntityRelationshipName %>")
    @JsonIgnore
        <%_ }
        } else if (databaseType === 'mongodb' || databaseType === 'couchbase') {
            if (databaseType === 'mongodb') { _%>
    @DBRef
        <%_ } _%>
    @Field("<%= relationshipFieldName %>")
        <%_ if (databaseType === 'couchbase') { _%>
    private String <%= relationshipFieldName %>Id;

    @N1qlJoin(on = "lks.<%= relationshipFieldName %>=meta(rks).id", fetchType = FetchType.IMMEDIATE)
        <%_ }
            if (ownerSide === false) { _%>
    @com.fasterxml.jackson.annotation.JsonBackReference
    <%_     }
        } _%>
    private <%= asEntity(otherEntityNameCapitalized) %> <%= relationshipFieldName %>;

    <%_ }
    } _%>
    // jhipster-needle-entity-add-field - JHipster will add fields here, do not remove
    public <% if (databaseType === 'sql') { %><%= primaryKeyType %><% } %><% if (databaseType === 'mongodb' || databaseType === 'couchbase') { %>String<% } %><% if (databaseType === 'cassandra') { %>UUID<% } %> getId() {
        return id;
    }

    public void setId(<% if (databaseType === 'sql') { %><%= primaryKeyType %><% } %><% if (databaseType === 'mongodb' || databaseType === 'couchbase') { %>String<% } %><% if (databaseType === 'cassandra') { %>UUID<% } %> id) {
        this.id = id;
    }
<%_ for (idx in fields) {
        const fieldType = fields[idx].fieldType;
        const fieldTypeBlobContent = fields[idx].fieldTypeBlobContent;
        const fieldName = fields[idx].fieldName;
        const fieldInJavaBeanMethod = fields[idx].fieldInJavaBeanMethod; _%>

    <%_ if (fieldTypeBlobContent !== 'text') { _%>
    public <%= fieldType %> <% if (fieldType.toLowerCase() === 'boolean') { %>is<% } else { %>get<%_ } _%><%= fieldInJavaBeanMethod %>() {
    <%_ } else { _%>
    public String get<%= fieldInJavaBeanMethod %>() {
    <%_ } _%>
        return <%= fieldName %>;
    }
    <%_ if (fluentMethods) { _%>

        <%_ if (fieldTypeBlobContent !== 'text') { _%>
    public <%= asEntity(entityClass) %> <%= fieldName %>(<%= fieldType %> <%= fieldName %>) {
        <%_ } else { _%>
    public <%= asEntity(entityClass) %> <%= fieldName %>(String <%= fieldName %>) {
        <%_ } _%>
        this.<%= fieldName %> = <%= fieldName %>;
        return this;
    }
    <%_ } _%>

    <%_ if (fieldTypeBlobContent !== 'text') { _%>
    public void set<%= fieldInJavaBeanMethod %>(<%= fieldType %> <%= fieldName %>) {
    <%_ } else { _%>
    public void set<%= fieldInJavaBeanMethod %>(String <%= fieldName %>) {
    <%_ } _%>
        this.<%= fieldName %> = <%= fieldName %>;
    }
    <%_ if ((fieldType === 'byte[]' || fieldType === 'ByteBuffer') && fieldTypeBlobContent !== 'text') { _%>

    public String get<%= fieldInJavaBeanMethod %>ContentType() {
        return <%= fieldName %>ContentType;
    }
    <%_ if (fluentMethods) { _%>

    public <%= asEntity(entityClass) %> <%= fieldName %>ContentType(String <%= fieldName %>ContentType) {
        this.<%= fieldName %>ContentType = <%= fieldName %>ContentType;
        return this;
    }
    <%_ } _%>

    public void set<%= fieldInJavaBeanMethod %>ContentType(String <%= fieldName %>ContentType) {
        this.<%= fieldName %>ContentType = <%= fieldName %>ContentType;
    }
    <%_ } _%>
<%_ } _%>
<%_
    for (idx in relationships) {
        const relationshipFieldName = relationships[idx].relationshipFieldName;
        const relationshipFieldNamePlural = relationships[idx].relationshipFieldNamePlural;
        const relationshipType = relationships[idx].relationshipType;
        const otherEntityNameCapitalized = relationships[idx].otherEntityNameCapitalized;
        const relationshipNameCapitalized = relationships[idx].relationshipNameCapitalized;
        const relationshipNameCapitalizedPlural = relationships[idx].relationshipNameCapitalizedPlural;
        const otherEntityName = relationships[idx].otherEntityName;
        const otherEntityNamePlural = relationships[idx].otherEntityNamePlural;
        const otherEntityRelationshipNameCapitalized = relationships[idx].otherEntityRelationshipNameCapitalized;
        const otherEntityRelationshipNameCapitalizedPlural = relationships[idx].otherEntityRelationshipNameCapitalizedPlural;
    _%>
    <%_ if (relationshipType === 'one-to-many' || relationshipType === 'many-to-many') { _%>

    public Set<<%= asEntity(otherEntityNameCapitalized) %>> get<%= relationshipNameCapitalizedPlural %>() {
        return <%= relationshipFieldNamePlural %>;
    }
        <%_ if (fluentMethods) { _%>

    public <%= asEntity(entityClass) %> <%= relationshipFieldNamePlural %>(Set<<%= asEntity(otherEntityNameCapitalized) %>> <%= otherEntityNamePlural %>) {
        this.<%= relationshipFieldNamePlural %> = <%= otherEntityNamePlural %>;
            <%_ if (databaseType === 'couchbase') { _%>
        this.<%= relationshipFieldName %>Ids = <%= otherEntityNamePlural %>.stream()
            .map(<%= asEntity(otherEntityNameCapitalized) %>::getId)
            .collect(Collectors.toSet());
            <%_ } _%>
        return this;
    }

    public <%= asEntity(entityClass) %> add<%= relationshipNameCapitalized %>(<%= asEntity(otherEntityNameCapitalized) %> <%= otherEntityName %>) {
        this.<%= relationshipFieldNamePlural %>.add(<%= otherEntityName %>);
            <%_ if (databaseType === 'couchbase') { _%>
        this.<%= relationshipFieldName %>Ids.add(<%= otherEntityName %>.getId());
            <%_ } _%>
            <%_ if (relationshipType === 'one-to-many') { _%>
        <%= otherEntityName %>.set<%= otherEntityRelationshipNameCapitalized %>(this);
            <%_ } else if (otherEntityRelationshipNameCapitalizedPlural !== '' && asEntity(otherEntityNameCapitalized)!=='User' && relationshipType === 'many-to-many') {
                // JHipster version < 3.6.0 didn't ask for this relationship name _%>
        <%= otherEntityName %>.get<%= otherEntityRelationshipNameCapitalizedPlural %>().add(this);
            <%_ } _%>
        return this;
    }

    public <%= asEntity(entityClass) %> remove<%= relationshipNameCapitalized %>(<%= asEntity(otherEntityNameCapitalized) %> <%= otherEntityName %>) {
        this.<%= relationshipFieldNamePlural %>.remove(<%= otherEntityName %>);
            <%_ if (databaseType === 'couchbase') { _%>
        this.<%= relationshipFieldName %>Ids.remove(<%= otherEntityName %>.getId());
            <%_ } _%>
            <%_ if (relationshipType === 'one-to-many') { _%>
        <%= otherEntityName %>.set<%= otherEntityRelationshipNameCapitalized %>(null);
            <%_ } else if (otherEntityRelationshipNameCapitalizedPlural !== '' && asEntity(otherEntityNameCapitalized)!=='User' && relationshipType === 'many-to-many') {
                // JHipster version < 3.6.0 didn't ask for this relationship name _%>
        <%= otherEntityName %>.get<%= otherEntityRelationshipNameCapitalizedPlural %>().remove(this);
            <%_ } _%>
        return this;
    }
        <%_ } _%>

    public void set<%= relationshipNameCapitalizedPlural %>(Set<<%= asEntity(otherEntityNameCapitalized) %>> <%= otherEntityNamePlural %>) {
        this.<%= relationshipFieldNamePlural %> = <%= otherEntityNamePlural %>;
        <%_ if (databaseType === 'couchbase') { _%>
        this.<%= relationshipFieldName %>Ids = <%= otherEntityNamePlural %>.stream()
            .map(<%= asEntity(otherEntityNameCapitalized) %>::getId)
            .collect(Collectors.toSet());
        <%_ } _%>
    }
    <%_ } else { _%>

    public <%= asEntity(otherEntityNameCapitalized) %> get<%= relationshipNameCapitalized %>() {
        return <%= relationshipFieldName %>;
    }
        <%_ if (fluentMethods) { _%>

    public <%= asEntity(entityClass) %> <%= relationshipFieldName %>(<%= asEntity(otherEntityNameCapitalized) %> <%= otherEntityName %>) {
        this.<%= relationshipFieldName %> = <%= otherEntityName %>;
            <%_ if (databaseType === 'couchbase') { _%>
        this.<%= relationshipFieldName %>Id = <%= otherEntityName %>.getId();
            <%_ } _%>
        return this;
    }
        <%_ } _%>

    public void set<%= relationshipNameCapitalized %>(<%= asEntity(otherEntityNameCapitalized) %> <%= otherEntityName %>) {
        this.<%= relationshipFieldName %> = <%= otherEntityName %>;
        <%_ if (databaseType === 'couchbase') { _%>
        this.<%= relationshipFieldName %>Id = <%= otherEntityName %>.getId();
        <%_ } _%>
    }
    <%_ } _%>
<%_ } _%>
    // jhipster-needle-entity-add-getters-setters - JHipster will add getters and setters here, do not remove

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (!(o instanceof <%= asEntity(entityClass) %>)) {
            return false;
        }
        return id != null && id.equals(((<%= asEntity(entityClass) %>) o).id);
    }

    @Override
    public int hashCode() {
        return 31;
    }

    @Override
    public String toString() {
        return "<%= asEntity(entityClass) %>{" +
            "id=" + getId() +
            <%_ for (idx in fields) {
                const fieldType = fields[idx].fieldType;
                const fieldTypeBlobContent = fields[idx].fieldTypeBlobContent;
                const fieldName = fields[idx].fieldName;
                const fieldInJavaBeanMethod = fields[idx].fieldInJavaBeanMethod;
                const isNumeric = ['integer', 'long', 'float', 'double', 'bigdecimal'].includes(fieldType.toLowerCase()); _%>
            ", <%= fieldName %>=<% if (! isNumeric) {%>'<% } %>" + <% if (fieldType.toLowerCase() === 'boolean') { %>is<% } else { %>get<% } %><%= fieldInJavaBeanMethod %>() <% if (! isNumeric) { %>+ "'" <% } %>+
                <%_ if ((fieldType === 'byte[]' || fieldType === 'ByteBuffer') && fieldTypeBlobContent !== 'text') { _%>
            ", <%= fieldName %>ContentType='" + get<%= fieldInJavaBeanMethod %>ContentType() + "'" +
                <%_ } _%>
            <%_ } _%>
            "}";
    }
}
